package cn.jhz.learn.blog.component;

import cn.jhz.learn.blog.po.blogger.BlogBlogger;

import javax.servlet.http.HttpServletRequest;


public class RequestHolder {

	private static final ThreadLocal<BlogBlogger> userHolder = new ThreadLocal<>();

	private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<>();

	private static final ThreadLocal<Integer> operateCode = new ThreadLocal<>();

	public static void add(BlogBlogger sysUser) {
		userHolder.set(sysUser);
	}

	public static void add(HttpServletRequest request) {
		requestHolder.set(request);
	}

	public static BlogBlogger getCurrentUser() {
		return userHolder.get();
	}

	public static HttpServletRequest getCurrentRequest() {
		return requestHolder.get();
	}

	public static void setOperateCode(Integer code) {
		operateCode.set(code);
	}

	public static Integer getOperateCode() {
		Integer code = operateCode.get();
		operateCode.remove();
		return code;
	}

	public static void remove() {
		userHolder.remove();
		requestHolder.remove();
	}
}
